import Vue from 'vue'
import App from './App.vue'
import router from './router'
// import './plugins/element.js'
import './assets/css/global.css'
// 导入字体图标
import './assets/fonts/iconfont.css'
// 导入axios
import axios from 'axios'
// 导入vue-table-with-tree
import treeTable from 'vue-table-with-tree-grid'
// 导入'vue-quill-editor'富文本编辑器
import VueQuillEditor from 'vue-quill-editor'

// 导入进度条的功能//导入nprogress的样式表
import nprogress from 'nprogress'

// 配置请求的根路径
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/'
// 对响应的数据进行处理
axios.interceptors.response.use(
  response => {
    // Do something before response is sent
    nprogress.done()
    return response.data
  },
  error => {
    // Do something with response error
    // 解构方法计入 { data: res } res是用于代替data这个值的
    return Promise.reject(error)
  }
)
// 请求添加authorization请求头
axios.interceptors.request.use(
  config => {
    // Do something before request is sent
    config.headers.Authorization = sessionStorage.getItem('token')
    nprogress.start()
    return config
  },
  error => {
    // Do something with request error
    return Promise.reject(error)
  }
)

Vue.component('table-tree', treeTable)
Vue.prototype.$http = axios
Vue.config.productionTip = false
// 定义全局的过滤器用于时间格式的处理
Vue.filter('dateFormat', function(originValue) {
  const dt = new Date(originValue)

  const y = dt.getFullYear()
  const M = (dt.getMonth() + 1 + '').padStart(2, '0')
  const D = (dt.getDate() + '').padStart(2, '0')

  const h = (dt.getHours() + '').padStart(2, '0')
  const m = (dt.getMinutes() + '').padStart(2, '0')
  const s = (dt.getSeconds() + '').padStart(2, '0')

  return `${y}-${M}-${D} ${h}:${m}:${s}`
})
// 注册VueQuillEditor
Vue.use(VueQuillEditor)

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
